package com.yh.arget;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

import java.util.Arrays;

public class MyAspect {
    //前置增强方法
    public void before(){
        System.out.println("前置通知");
    }
    //后置增强方法
    public void after(){
        System.out.println("后置通知");
    }
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕通知");
        Object[] args = joinPoint.getArgs();//获取请求参数
        Object proceed = joinPoint.proceed(args);//调用源方法
        System.out.println("环绕通知");
        // ProceedingJoinPoint 环绕通知中使用的获取原方法的参数
        //getArgs()获取原方法请求执行时传入的参数
        //proceed(args)调用执行原方法传入参数
        return proceed;
    }
    public void afterThrowing(Exception e){
        System.out.println("异常通知");
        System.out.println(e);
    }
    public void returning(JoinPoint joinPoint, Object result) throws Throwable{
        System.out.println("返回通知");
        System.out.println(Arrays.toString(joinPoint.getArgs()));
        System.out.println(result);
    }
}
